<cvc-entity-select
  [cvcSelectMode]="props.isMultiSelect ? 'multiple' : 'default'"
  [cvcCustomTemplate]="selectedTemplate"
  [cvcFormControl]="formControl"
  [cvcFormlyAttributes]="field"
  [cvcEntityName]="props.entityName"
  [cvcPlaceholder]="placeholder$ | ngrxPush"
  [cvcResults]="result$ | ngrxPush"
  [cvcOptions]="selectOption$ | ngrxPush"
  [cvcShowError]="showError"
  [cvcDisabled]="onRequiresPhenotype$ && !(onRequiresPhenotype$ | ngrxPush)"
  [cvcLoading]="isLoading$ | ngrxPush"
  (cvcOnSearch)="onSearch$.next($event)"
  (cvcOnOpenChange)="onOpenChange$ ? onOpenChange$.next($event) : null"
  (cvcOnModelChange)="props.change && props.change(field, $event)">
</cvc-entity-select>

<!-- select option templates -->
<!-- result$ updates generate an array of #optionTemplates. entity-tag-field.mixin watches #optionTemplates changes, and attaches each to an NzSelectOptionTemplateInterface an object, which are emitted from selectOption$. selectOption$ is passed to <cvc-entity-select> via [cvcOptions] above -->
<ng-container *ngrxLet="onSearch$ as searchString">
  <ng-container *ngFor="let result of result$ | ngrxPush; index as i">
    <ng-template #optionTemplates>
      <cvc-entity-tag
        [cvcDisableLink]="true"
        [cvcCacheId]="result.__typename + ':' + result.id"
        [cvcEmphasize]="searchString"></cvc-entity-tag>
      <span
        nz-typography
        nzType="secondary">
        <ng-container *ngIf="result.hpoId">
          <em>
            <span
              nz-typography
              nzType="secondary"
              [innerHtml]="
                result.hpoId | highlightTypeahead : searchString
              "></span
          ></em>
        </ng-container>
      </span>
    </ng-template>
  </ng-container>
</ng-container>

<!-- selected option item template -->
<!-- displays entity tag, specifying context and mode depending on
    if field is multi-select or single -->
<ng-template
  #selectedTemplate
  let-selected>
  <div class="ant-select-selection-item-content">
    <cvc-entity-tag
      [cvcCacheId]="'Phenotype:' + selected.nzValue"
      [cvcContext]="props.isMultiSelect ? 'multi-select-item' : 'select-item'"
      [cvcMode]="props.isMultiSelect ? 'default' : 'closeable'"
      (cvcOnClose)="onTagClose$.next(selected.nzValue)"></cvc-entity-tag>
  </div>
</ng-template>
